1
Foundations of LLM Prompting for Developers
AI010 Lesson 1
00:00

The Shift to Instruction-Tuned Models

What is the Foundation?

In the past, Base LLMs were trained primarily to predict the next word in a sequence based on vast amounts of data. However, for developers, the real power lies in Instruction Tuned LLMs. These models are refined using Reinforcement Learning from Human Feedback (RLHF) to follow specific commands and act as helpful assistants.

The Golden Rule: Treat the LLM like a smart but literal intern. It lacks your specific context, so you must be explicit about your goals.

How to Apply Core Principles

  1. Clarity and Specificity: Clarity does not mean brevity. Providing more context and using delimiters (like triple backticks or XML tags) helps the model distinguish your instructions from the data it needs to process.
  2. Give the Model Time to Think: Complex tasks require a chain of thought. If you ask a model to jump straight to a conclusion, it is more likely to make a reasoning error. Instruct it to work out its own solution first.
Avoid Hallucinations
Models can generate "plausible-sounding" but false information. Always verify facts or instruct the model to cite its sources to mitigate this risk.
main.py
TERMINAL bash — 80x24
> Ready. Click "Run" to execute.
>
Question 1
Why should a developer prefer an Instruction Tuned LLM over a Base LLM for building an application?
Base LLMs are better at following complex instructions.
Instruction Tuned LLMs are trained to follow tasks and are less likely to simply "complete" the text.
Base LLMs never hallucinate.
Challenge: Generating Structured Data
Apply prompting principles to format output.
You have a list of ingredients. You need to convert this list into a JSON format for a web app.
Task
Write a prompt that requests JSON output with keys for 'item' and 'quantity'. Include a condition check: If the input is not a recipe, output "No recipe detected."
Solution:
prompt = "You will be provided with text. If it contains a recipe, convert it to JSON with keys 'item' and 'quantity'. If not, write 'No recipe detected.' Text: <user_input>"